package com.qfmy.controller.common;


import com.qfmy.service.common.FileUploadService;
import common.result.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件上传控制层
 */
@RequestMapping("/app/file")
@RestController
@SuppressWarnings("all")
public class FileUploadController {

	/**
	 * 注入文件上传服务
	 */
	@Resource
	private FileUploadService fileUploadService;

	/**
	 *文件上传方法
	 */
	@PostMapping("/upload")
	public Result<String> upload(@RequestParam MultipartFile file) throws Exception {
		// 上传文件
		String url = fileUploadService.upload(file);
		return Result.ok(url);
	}

	/**
	 * 接收1上传的pdf文件
	 */
	@PostMapping("/uploadPdf")
	public Result<String> uploadPdf(@RequestParam MultipartFile file) throws Exception {
		//获取pdf里面的文件内容
		String content = fileUploadService.uploadPdf(file);
		return Result.ok(content);
	}

}
